package st0004;

class Solution2 {//这种思路不行，复杂度为m+n,放弃
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        double result;
        int len=nums1.length+nums2.length;
        int i=0,j=0,count=0,pre=0;
        if(len%2==0){
            while (count<=len/2){
                if(i<nums1.length&&nums1[i]<nums2[j]){
                    pre=nums1[i];
                    i++;
                }else {
                    pre=nums1[j];
                    j++;
                }
                count++;
            }
            int next;
            if(i==nums1.length){
                next=nums2[j];
            }else if(j==nums2.length){
                next=nums1[i];
            }else if(nums1[i]<nums2[j]){
                next=nums1[i];
            }else{
                next=nums2[j];
            }
            result=(double)(pre+next)/2;
        }else {
            while (count<=len/2+1){
                if(i<nums1.length&&nums1[i]<nums2[j]){
                    pre=nums1[i];
                    i++;
                }else {
                    pre=nums1[j];
                    j++;
                }
                count++;
            }
            result=(double)pre;
        }
        return result;
    }
    public static void main(String[] args) {
        Solution2 a = new Solution2();
        int[] q={1,3},w={2};
        a.findMedianSortedArrays(q,w);
        System.out.println("");
    }
}
